/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SeleccionarCliente.java
 *
 * Created on 15/05/2011, 07:12:10 PM
 */
package repproyectobases;

import java.util.ArrayList;


/**
 *
 * @author Bladelaire
 */
public class SeleccionarCliente extends javax.swing.JInternalFrame {
    
    private Control ctrl;
    private Factura f;
    static private Interfaz in;
    private ArrayList<String> comboClientes;

    /** Creates new form SeleccionarCliente */
    public SeleccionarCliente(Control ctrl,Interfaz miIn) {
        initComponents();
        this.ctrl = ctrl;
        SeleccionarCliente.in=miIn;
        this.setTitle("Seleccionar Cliente - By Luis&Luis");
        initComponents();
        inicializarCombo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        setTitle("Selecione un cliente  en el campo indicado");

        jLabel1.setText("Indique el cliente:  ");

        jButton1.setText("Ingresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox1, 0, 249, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inicializarCombo()
    {
        //comboClientes = new String [ctrl.getComboCliente().length];
        comboClientes = ctrl.getComboCliente();
        for(int i=comboClientes.size()-1;i>=0;i--)
        {
            jComboBox1.addItem(comboClientes.get(i));
        }
        jComboBox1.repaint();
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if(evt.getSource()==jButton1)
        {
            String m=(String)jComboBox1.getSelectedItem();
            String []mm=m.split("-");
            f = new Factura(ctrl,mm[0],"1");
            in.getInternalPanel().add(f);
            f.show();
            this.hide();
            //System.out.println(jComboBox1.getSelectedItem());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
